<%-- 
/*
Assignment 1
Class ID        : SE0691
Group           : 1
Due Date        : 20 November 2012
I declare that this assignment is my own work
in accordance with FPT Policy.
*/
--%>

<%@page import="edu.fpt.hib.Services"%>
<%@page import="edu.fpt.dal.ServicesDAL"%>
<%@page import="edu.fpt.hib.Apartment"%>
<%@page import="edu.fpt.dal.ApartmentDAL"%>
<%@page import="edu.fpt.dal.UsersDAL"%>
<%@page import="edu.fpt.hib.Users"%>
<%@page import="edu.fpt.hib.RequestServices"%>
<%@page import="java.util.ArrayList"%>
<%@page import="edu.fpt.dal.RequestServicesDAL"%>
<%@page contentType="text/html" pageEncoding="UTF-8"%>
<%@taglib prefix="myTag" uri="/WEB-INF/tlds/taglib.tld" %>
<!DOCTYPE html>
<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        <title>Request Management</title>
        <style type="text/css"> <!--@import url("../style.css");--></style>
        <script>function goBack()  {  window.history.back()  }</script>
    </head>
    <body>
        <%@include file="template/header.jsp" %>
        <div id="page">

            <table style="width: 950px;">
                <tr>
                    <td style="float: left;"><form method="post" action="createuser.jsp">
                            <input class="searchsubmit" type="submit" name="Submit" value="Create new user">
                        </form></td>
                    <td style="float: right;"><form method="get" action="searchuser.jsp">
                            <input id="searchinput" type="text" name="keyword" required="">
                            <input class="searchsubmit" type="submit" name="Submit" value="Search">
                        </form></td>
                </tr>
            </table>
            <hr>
            <% ArrayList<RequestServices> list = RequestServicesDAL.listAllPeding();
                if (list != null) {%>


            <div class="post">
                <h2 class="title">List All Pending Request</h2>
                <table id="mytable" cellspacing="0">
                    <tr>
                        <th scope="col" class="nobg">User</th>
                        <th scope="col">At Apartment</th>
                        <th scope="col">Services</th>
                        <th scope="col" colspan="2">Action</th>
                    </tr>   
                    <%

                        for (RequestServices req : list) {
                            Users user = UsersDAL.getUsersHQL(req.getUsers().getUserId());
                            Services service = ServicesDAL.getByServicesID(req.getServices().getServiceId());
                            Apartment apart = ApartmentDAL.getApartmentByUserHQL(user.getUserId());
                    %>
                    <tr><th class="spec"><a href="detailuser.jsp?userid=<%=user.getUserId()%>"><%=user.getUserId()%></a></td>
                        <td class="spec"><a href="detailapartment.jsp?apartid=<%=apart.getApartId()%>"><%=apart.getApartId()%></a></td>
                        <td class="spec"><a href="detailservices.jsp?serviceid=<%=service.getServiceId()%>"><%=service.getServiceName()%></a></td>
                        <td class="spec">
                            <form method="post" action="../ProcessRequest">
                                <input type="hidden" value="<%=user.getUserId()%>" name="userid">
                                <input type="hidden" value="<%=service.getServiceId()%>" name="serviceid">
                                <input type="hidden" value="accept" name="action">
                                <input class="searchsubmit" type="submit" value="Approve Request">
                            </form></td>
                    <td><form method="post" action="../ProcessRequest">
                                <input type="hidden" value="<%=user.getUserId()%>" name="userid">
                                <input type="hidden" value="<%=service.getServiceId()%>" name="serviceid">
                                <input type="hidden" value="deny" name="action">
                                <input class="searchsubmit" type="submit" value="Reject Request">
                            </form>
                        </td>
                    </tr>
                    <% }%>
                </table>
            </div>
        </div>
        <% } else {%>
        <div class="post">
            <h2 class="title">No request! Introduce new Services :D</h2>
        </div>
        <%}%>
        <%@include file="template/footer.jsp" %>
    </body>
</html>
